import requests

from odoo import api, fields, models
from odoo.exceptions import ValidationError


class RoApiLog(models.Model):
    _name = 'ro.api.log'
    _inherit = 'ro.api.base'
    _description = '接口请求日志'

    name = fields.Char('序号')
    host = fields.Char('HOST')
    status = fields.Char('STATUS')
    path = fields.Char('PATH')
    method = fields.Char('METHOD')
    type = fields.Selection([('out', '出站'), ('in', '进站')], string='类别')
    message = fields.Text('MESSAGE')
    body = fields.Text('BODY')
    api_method = fields.Char('接口类型')

    @api.model
    def create(self, vals):
        user_id = self.env['res.users'].browse(1)
        vals['name'] = self.env['ir.sequence'].with_user(user_id).next_by_code('ro.api.log')
        return super(RoApiLog, self).create(vals)
